/**************************************************
|	File:		CHowToPlayState.cpp
|	Author:		Benjamin Budian
|	Course:		SGD
|	Purpose:	CHowToPlayState - shows the rules and controls for the game
**************************************************/
#include "HowToPlayState.h"

//Wrappers
#include "../SGD Wrappers/CSGD_XAudio2.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/SGD_String.h"

//Local
#include "Game.h"
#include "MainMenuState.h"
#include "CellAnimation.h"

#include "../SGD Wrappers/CSGD_TextureManager.h"

CHowToPlayState::CHowToPlayState(void){}

CHowToPlayState::~CHowToPlayState(void){}

CHowToPlayState* CHowToPlayState::GetInstance(){
	static CHowToPlayState s_Instance;
	return &s_Instance;
}

void CHowToPlayState::Enter(){
	m_pPlayer = new CCellAnimation();
	m_pEnemy = new CCellAnimation();

	m_pEnemy->Initialize(64,64,13,130,9,true,_T("resource/images/Player/bb_skeleton.png"));
	m_pPlayer->Initialize(64,64,13,130,9,true,_T("resource/images/Player/bb_tannedmale(resized).png"));
	m_nArmorImgID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/images/Player/Golden Armor/Male/bb_Armor_Drops.png"));

	m_pEnemy->Play(true, 1.0f);
	m_pPlayer->Play(true, 1.0f);
}

void CHowToPlayState::Exit(){
	delete m_pPlayer;
	delete m_pEnemy;
}

bool CHowToPlayState::Input(){
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();

	if(pDI->KeyPressed(DIK_ESCAPE) == true){
		CGame::GetInstance()->ChangeState( CMainMenuState::GetInstance() );
	}
	return true;
}

void CHowToPlayState::Update( float fElapsedTime ){
	m_pPlayer->Update(fElapsedTime);
	m_pEnemy->Update(fElapsedTime);
}

void CHowToPlayState::Render(){
	CBitmapFont* pFont = CGame::GetInstance()->GetFont();

	int nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("How To Play")*64)/2;
	pFont->Draw( _T("How To Play"), nCenterOffset, 100, 2.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("Objective")*32)/2;
	pFont->Draw( _T("Objective"), nCenterOffset, 300, 1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("Kill all the enemies")*16)/2;
	pFont->Draw( _T("Kill all the enemies"), nCenterOffset, 350, 0.5f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("to escape the room!")*16)/2;
	pFont->Draw( _T("to escape the room!"), nCenterOffset, 375, 0.5f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("Controls")*32)/2;
	pFont->Draw( _T("Controls"), nCenterOffset, 450, 1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("W A S D - Movement")*16)/2;
	pFont->Draw( _T("W A S D - Movement"), nCenterOffset, 500, 0.5f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("SPACE - Attack")*16)/2;
	pFont->Draw( _T("SPACE - Attack"), nCenterOffset, 525, 0.5f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("Pick-ups")*32)/2;
	pFont->Draw( _T("Pickups"), nCenterOffset, 600, 1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	nCenterOffset = CGame::GetInstance()->GetScreenWidth()/2 - (strlen("Armor:")*16)/2;
	pFont->Draw( _T("Armor:"), nCenterOffset, 625, 0.5f, D3DCOLOR_ARGB(255, 255, 255, 255) );

	m_pPlayer->Render(100,500,1.0f, D3DCOLOR_ARGB(255, 255, 255, 255) );
	m_pEnemy->Render(800,500,1.0f,  D3DCOLOR_ARGB(255, 255, 255, 255) );

	RECT rRect;
	for(int i = 0; i < 6; i++){
		rRect.left = (32 * i);
		rRect.right = rRect.left + 32;
		rRect.top = 0;
		rRect.bottom = 32;
		CSGD_TextureManager::GetInstance()->Draw(m_nArmorImgID,CGame::GetInstance()->GetScreenWidth()/2 - 180 + (i*50),675, 1.0f,1.0f,&rRect);
	}

}

